package com.example.controller.configuration;

import com.example.bean.configuration.XiangZhiGuanLi;
import com.example.bean.configuration.ZhiBiaoGuanLi;
import com.example.bean.configuration.vo.ZhiBiaoGuanLiVo;
import com.example.service.configuration.ZhiBiaoGuanLiService;
import com.example.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/zhibiaoguanli")
public class ZhiBiaoGuanLiController {

    @Autowired
    ZhiBiaoGuanLiService service;

    @PostMapping("/page")
    public PageInfo<ZhiBiaoGuanLi> page(@RequestBody ZhiBiaoGuanLiVo vo){
        return service.getpage(vo);
    }

    @PostMapping("/addzbgl")
    public Result addzbgl(@RequestBody ZhiBiaoGuanLi zhiBiaoGuanLi){
        System.out.println(zhiBiaoGuanLi);
        Integer flag = service.addzbgl(zhiBiaoGuanLi);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    @GetMapping("/{aid}")
    public Result getById(@PathVariable String aid){
        ZhiBiaoGuanLi zhiBiaoGuanLi = service.getId(aid);
        Result result = new Result();
        if(zhiBiaoGuanLi != null){
            result.ok();
            result.setData(zhiBiaoGuanLi);
        }else {
            result.fail("失败");
        }
        return result;
    }

    @PostMapping("/updatezbgl")
    public Result edit(@RequestBody ZhiBiaoGuanLi zhiBiaoGuanLi){
        System.out.println(zhiBiaoGuanLi);
        Integer flag = service.editzbgl(zhiBiaoGuanLi);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    //批量删除
    @PostMapping("/dels")
    public Result dels(@RequestBody List<String> ids){
        //删除
        Integer flag = service.dels(ids);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else {
            result.fail("失败");
        }
        return result;
    }
}
